package com.mdd.front.controller;

import com.mdd.common.core.AjaxResult;
import com.mdd.front.LikeFrontThreadLocal;
import com.mdd.front.service.IUserSigninService;
import com.mdd.front.validate.PageParam;
import com.mdd.front.vo.user.UserSiginDetail;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户签到管理
 * @author panweiliang
 */
@RestController
@RequestMapping("api/user/signin")
public class UserSigninController {

    @Resource
    IUserSigninService iUserSigninService;

    /**
     * 用户签到详情
     *
     * @author panweiliang
     * @return Object
     */
    @GetMapping("/detail")
    public Object detail() {
        Integer userId = LikeFrontThreadLocal.getUserId();
        UserSiginDetail userSiginDetail = iUserSigninService.detail(userId);
        return AjaxResult.success(userSiginDetail);
    }

    /**
     * 用户签到新增
     *
     * @author panweiliang
     * @return Object
     */
    @PostMapping("/add")
    public Object add() {
        Integer userId = LikeFrontThreadLocal.getUserId();
        return AjaxResult.success(iUserSigninService.add(userId));
    }

    /**
     * 我的积分流水
     *
     * @author panweiliang
     * @return Object
     */
    @GetMapping("/logs")
    public Object getLogs(@Validated PageParam pageParam, @RequestParam(value = "action", required = false) Integer action) {
        return AjaxResult.success(iUserSigninService.getPointsLog(pageParam, action, LikeFrontThreadLocal.getUserId()));
    }

}
